<?php
CUserAuth::hasAccess(STATUS_MITARBEITER_SCHREIBEN);

include_once '_TEST/Matias/testFunctions.php';
/** costumers_create.php
 * Project name: project_name
 * Created on: 28.10.2011
 * Author: Matias Thomsen
 * 
 * Eingabemaske für die Eintragung eines Neukunden
 * Nach dem Absenden werden die Daten überprüft und ggf. Fehlermeldungen
 * ausgegeben
 */

//TODO deactivate auto complete on textfields

if (isset($_POST['abort'])) {
        header("LOCATION: ?page=customer-view");
        die("Fatal error!");
}
//-----INCLUDES-----
    include_once 'class/customer/CCustomerMapper.php';
//-----INCLUDES END-----

    
    
//-----DATABASE CONNECTION-----
    $db = new CCustomerMapper($connArgs);
//-----DATABASE CONNECTION END-----


    
//-----VARS-----
    $sel1 = ""; $sel2 = ""; $sel3 = ""; $sel4 = ""; $sel5 = ""; $sel6 = ""; //select box
    $errors = array(); // array to sumarize errors
    $staff = $_SESSION['userID']; //employee logged in
    $gstelle = $_SESSION['gstelleId']; //employees' workstation
    $show_editForm = true;
//-----VARS END-----


    
//-----FORMULAR DATA-----
//Needed for comboboxes

//betreuer array
        $query = "SELECT `idMitarbeiter`, `name`, `vorname` 
                    FROM `Mitarbeiter`
                    WHERE `gstelleId` = '$gstelle'";
            $stm = $db->prepare($query);
            $stm->execute();
        $betreuer = $stm->fetchAll(PDO::FETCH_ASSOC);
    
//branche array
        $query = "SELECT * 
                    FROM `Branche`";
            $stm = $db->prepare($query);
            $stm->execute();
        $branchen = $stm->fetchAll(PDO::FETCH_ASSOC);
    
//beruf array
        $query = "SELECT *
                    FROM `Beruf`";
            $stm = $db->prepare($query);
            $stm->execute();
        $berufe = $stm->fetchAll(PDO::FETCH_ASSOC);
    
//berufGruppe array
        $query = "SELECT * 
                    FROM `Berufsgruppe`";
            $stm = $db->prepare($query);
            $stm->execute();
        $berufsgruppe = $stm->fetchAll(PDO::FETCH_ASSOC);

//-----FORMULAR DATA END-----


//-----IF CREATE FORM IS FIRED-----
if ( isset($_POST['mark']) ||  isset($_POST['save']) ){
        $customer = new CCustomer();

//anrede--------------------------------------------------------------------
        if ( isset( $_POST['anrede'] ) && $_POST['anrede'] != ""){
                switch ( $_POST['anrede'] ) {
                    case '1': $customer->setAnrede("herr"); break;
                    case '2': $customer->setAnrede("frau"); break;
                    
                    default: 
                        if ( isset($_POST['mark']) ){
                            $errors[] = "Bitte wählen Sie die passende Anrede";
                        }elseif( isset($_POST['save']) ){
                            $customer->setAnrede("NA");
                        }
                        
                        break;
                }
        }else{ die("Fatal error!"); }

//titel--------------------------------------------------------------------
        if ( isset( $_POST['titel'] ) && $_POST['titel'] != ""){
                switch ( $_POST['titel'] ) {
                    case '1': $customer->setTitel("kein_titel"); break;
                    case '2': $customer->setTitel("dr"); break;
                    case '3': $customer->setTitel("prof"); break;
                    case '4': $customer->setTitel("dr_prof"); break;

                    default: $customer->setTitel("kein_titel"); break;
                }
        }else { die("Fatal error!"); }

//vorname--------------------------------------------------------------------
        if ( isset( $_POST['firstname'] ) && $_POST['firstname'] != ""){
                $customer->setName($_POST['firstname']);
        }else{
                $errors[] = "Bitte geben Sie den Vorname an.";
        }

//nachname--------------------------------------------------------------------
        if ( isset( $_POST['lastname'] ) && $_POST['lastname'] != ""){
                $customer->setNachname($_POST['lastname']);
        }else{
                $errors[] = "Bitte geben Sie den Nachname an.";
        }

//geburtsname-------------------------------------------------------------------
        if ( isset( $_POST['birthname'] ) && $_POST['birthname'] != ""){
                $customer->setGeburtsname($_POST['birthname']);
        }else{
                $customer->setGeburtsname(null);
        }

//strasse_nr--------------------------------------------------------------------
        if ( isset( $_POST['adress'] ) && $_POST['adress'] != ""){
                $customer->setStrasse_nr($_POST['adress']);
        }else{
                if ( isset($_POST['mark']) ){
                        $errors[] = "Bitte geben Sie die Adresse (Straße, Nummer) an";
                }elseif( isset($_POST['save']) ){
                        $customer->setStrasse_nr(null);
                }
        }

//plz---------------------------------------------------------------------------
        if ( isset( $_POST['zipcode'] ) && $_POST['zipcode'] != ""){
                $customer->setPlz($_POST['zipcode']);
        }else{
                if ( isset($_POST['mark']) ){
                        $errors[] = "Bitte geben Sie die PLZ an";
                }elseif( isset($_POST['save']) ){
                        $customer->setPlz(null);
                }
        }

//ort---------------------------------------------------------------------------
        if ( isset( $_POST['city'] ) && $_POST['city'] != ""){
                $customer->setOrt($_POST['city']);
        }else{
                if ( isset($_POST['mark']) ){
                        $errors[] = "Bitte geben Sie den Wohnort an.";
                }elseif( isset($_POST['save']) ){
                        $customer->setOrt(null);
                }
        }

//wohnhaftSeit------------------------------------------------------------------
        if ( isset( $_POST['livingsince'] ) && $_POST['livingsince'] != ""){
                $timestamp = strtotime($_POST['livingsince']);

                if (date("d.m.Y", $timestamp) == $_POST['livingsince']){
                        $customer->setWohnhaftSeit(date("Y-m-d", $timestamp));
                }else{
                        $errors[] = "Bitte geben Sie das Datum im richtigen Format ein (Feld: Wohnhaft Seit)";
                }
        }else{
                if ( isset($_POST['mark']) ){
                        $errors[] = "Bitte geben an, seit wann Sie bei der Aktuellen Adresse wohnen.";
                }elseif( isset($_POST['save']) ){
                        $customer->setWohnhaftSeit("0000-00-00");
                }
        }

//geburtsdatum------------------------------------------------------------------
        if ( isset( $_POST['birthdate'] ) && $_POST['birthdate'] != ""){
                $timestamp = strtotime($_POST['birthdate']);
                if (date("d.m.Y", $timestamp) == $_POST['birthdate']){
                        $customer->setGeburtsdatum(date("Y-m-d", $timestamp));
                }else{
                        $errors[] = "Bitte geben Sie das Datum im richtigen Format ein (Feld: Geburtsdatum)";
                }
        }else{
                if ( isset($_POST['mark']) ){
                        $errors[] = "Bitte geben Sie das Geburtsdatum an.";
                }elseif( isset($_POST['save']) ){
                        $customer->setGeburtsdatum("0000-00-00");
                }
        }

//fam_stand---------------------------------------------------------------------
        if ( isset( $_POST['fam_stand'] ) && $_POST['fam_stand'] != ""){
                switch ( $_POST['fam_stand'] ) {
                    case '1': $customer->setFamilienstand("1"); break;
                    case '2': $customer->setFamilienstand("2"); break;
                    case '3': $customer->setFamilienstand("3"); break;
                    case '4': $customer->setFamilienstand("4"); break;
                    case '5': $customer->setFamilienstand("5"); break;
                    case '6': $customer->setFamilienstand("6"); break;
                    
                    default: 
                        if ( isset($_POST['mark']) ){
                            $errors[] = "Bitte wählen Sie den passenden Familienstand";
                        }elseif( isset($_POST['save']) ){
                            $customer->setFamilienstand("NA");
                        }
                        break;
                }
        }else { die("Fatal Error"); }

//staatsange--------------------------------------------------------------------
        if ( isset( $_POST['nacionality'] ) && $_POST['nacionality'] != ""){
                $customer->setStaatsange($_POST['nacionality']);
        }else{
                if ( isset($_POST['mark']) ){
                        $errors[] = "Bitte geben Sie die Staatsangehörigkeit an.";
                }elseif( isset($_POST['save']) ){
                        $customer->setStaatsange(null);
                }
        }

//telefon_1---------------------------------------------------------------------
        if ( isset( $_POST['phone_1'] ) && $_POST['phone_1'] != ""){
                $customer->setTelefon_1($_POST['phone_1']);
        }else{
                $customer->setTelefon_1('');
        }

//telefon_2---------------------------------------------------------------------
        if ( isset( $_POST['phone_2'] ) && $_POST['phone_2'] != ""){
                $customer->setTelefon_2($_POST['phone_2']);
        }else{
                $customer->setTelefon_2('');
        }

//email-------------------------------------------------------------------------
        if ( isset( $_POST['email'] ) && $_POST['email'] != ""){
            if (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
                    $customer->setEmail($_POST['email']);
            }else{
                    if ( isset($_POST['mark']) ){
                            $errors[] = "Die angegebene E-Mail ist nicht gültig";
                    }elseif( isset($_POST['save']) ){
                            $customer->setEmail(null);
                    }
            }
                
        }else{
                $customer->setEmail('');
        }
        
//datenschutz-------------------------------------------------------------------
        if ( isset( $_POST['privacy'] ) ){
                if ( $_POST['privacy'] == "accepted" ){
                        $customer->setDatenschutz(1);
                }else{
                        $customer->setDatenschutz(0);
                }
        }else{
                $customer->setDatenschutz(0);
        }

//monatEinkommen----------------------------------------------------------------
        if ( isset( $_POST['month'] ) && $_POST['month'] != ""){
                $customer->setMonatEinkommen($_POST['month']);
        }else{
                if ( isset($_POST['mark']) ){
                        $errors[] = "Bitte geben Sie das Monatseinkommen an.";
                }elseif( isset($_POST['save']) ){
                        $customer->setExtraEinkommen(null);
                }
        }

//extraEinkommen----------------------------------------------------------------
        if ( isset( $_POST['extra'] ) && $_POST['extra'] != ""){
                $customer->setExtraEinkommen($_POST['extra']);
        }else{
                if ( isset($_POST['mark']) ){
                        $errors[] = "Bitte geben Sie das Extra Einkommen an.";
                }elseif( isset($_POST['save']) ){
                        $customer->setExtraEinkommen(null);
                }                
        }

//wohnsituation---------------------------------------------------------------------
        if ( isset( $_POST['living_at'] ) && $_POST['living_at'] != ""){
                switch ( $_POST['living_at'] ) {
                    case '1': $customer->setWohnsituation("miete"); break;
                    case '2': $customer->setWohnsituation("eltern"); break;
                    case '3': $customer->setWohnsituation("eigentum"); break;
                    
                    default: 
                        if ( isset($_POST['mark']) ){
                            $errors[] = "Bitte wählen Sie die passende Wohnsituation";
                        }elseif( isset($_POST['save']) ){
                            $customer->setWohnsituation("NA");
                        }
                        break;
                } 
        }else { die("Fatal Error"); }
//brancheId---------------------------------------------------------------------
        if ( isset( $_POST['sector'] ) && $_POST['sector'] != ""){
                $customer->setBrancheId($_POST['sector']);
        }else{
                $customer->setBrancheId(9999);
        }

//berufsgruppeId----------------------------------------------------------------
        if ( isset( $_POST['sector_group'] ) && $_POST['sector_group'] != ""){
                $customer->setBerufsgruppeId($_POST['sector_group']);
        }else{
                if ( isset($_POST['mark']) ){
                        $errors[] = "Bitte geben Sie die Berufsgruppe an.";
                }elseif( isset($_POST['save']) ){
                        $customer->setBerufsgruppeId(9999);
                }
                
        }

//berufId-----------------------------------------------------------------------
        if ( isset( $_POST['occupation'] ) && $_POST['occupation'] != ""){
                $customer->setBerufId($_POST['occupation']);
        }else{
                $customer->setBerufId(9999);
        }

//betreuerId--------------------------------------------------------------------
        if ( isset( $_POST['advisor'] ) && $_POST['advisor'] != "" && $_POST['advisor'] != 9999){
                $customer->setBetreuerId($_POST['advisor']);
        }else{
                $customer->setBetreuerId(null);
                
        }

        //SAVE IF NO ERRORS
        if ( count($errors) == 0 ){
                $nummer = $gstelle.(time()-10);
                $customer->setKundenNr($nummer);
                $customer->setGstelleId($gstelle);
                $customer->setBearbeiterId($staff);

                if (isset($_POST['mark'])){
                        $customer->setStatus(2); //marked
                        $result = $db->saveCustomer($customer); //save dataset
                        if ( $result == 1 ){
                            $customer->setStatus(2);
                            $customer->setInBearbeitung(1);
                            $result = $db->saveCustomer($customer); //save dataset
                            if ( $result != 1 ){
                                $errors[] = "Es ist leider ein Fehler auufgetreten";
                            }
                        }else{
                            $errors[] = "Es ist leider ein Fehler auufgetreten";
                        }
                        $message = "Der Kunde wurde zur Freigabe vorgemerkt.";
                }
                if (isset($_POST['save'])){
                        $customer->setStatus(6); //inactive for further modification
                        $result = $db->saveCustomer($customer); //save dataset
                        if ( $result == 1 ){
                            $customer->setStatus(6);
                            $customer->setInBearbeitung(1);
                            $result = $db->saveCustomer($customer); //save dataset
                            if ( $result != 1 ){
                                $errors[] = "Es ist leider ein Fehler auufgetreten";
                            }
                        }else{
                            $errors[] = "Es ist leider ein Fehler auufgetreten";
                        }
                        $message = "Der Kunde wurde gespeichert und kann später bearbeitet und zur Freigabe vorgemerkt werden.";
                }

                //display error or success message
                if ( $result != 1 ){
                        $errors[] = $result;
                }else{
                        $show_editForm = false; //disable form editing
                        ?>
                                <div id="message-box">
                                        <p><?= $message ?></p>
                                </div>
                        <?php
                }

        }
        //SAVE IF NO ERRORS
}//IF CREATE FORM IS FIRED END

?>

<?php
//IF OPTIONS FORM IS FIRED END
    if ( $show_editForm == true ){ //display editForm if true
?>
<!-- EDIT FORM START -->

<?php
    if ( count($errors) > 0 ){
?>
            <!-- Error message box -->
            <div class="display-errors-label">
                    Die Daten konnten nicht gespeichert werden
            </div>
            <div class="display-errors-massage">
                    <ul>
                    <?php
                        foreach ( $errors as $error ){
                                echo "<li>".$error."</li>";
                        }
                    ?>
                    </ul>
            </div>
<?php } ?>
<!-- Error message box end -->

<div class="form-customer-create">
	<!-- 2 columns -->
	<div class="form-customer-create-2cols">
		
		<!-- FORM-HEADLINE -->
		<div class="form-customer-create-headline">Standard angaben</div>
		<!-- FORM-HEADLINE END -->

		<!-- ########################################################## -->
		<!-- Form Start -->
                <form name = "create" method="POST" autocomplete="off" action="<?php echo $_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING']; ?>">
                        <!-- ########################################################## -->
                        <!-- Form element wrap -->
                        <div class="form-customer-create-input-wrap">
                                <div class="form-customer-create-label">Anrede*</div>
                                <div class="form-customer-create-input">
                                    <?php
                                    if ( isset($_POST['anrede']) ){
                                            switch ( $_POST['anrede'] ){
                                                case "1": $sel1 = " selected"; break;
                                                case "2": $sel2 = " selected"; break;
                                                default:  $sel1 = ""; $sel2 = ""; break;
                                            }
                                    }else{
                                            $sel1 = ""; $sel2 = "";
                                    }
                                    ?>
                                        <select name="anrede">
                                                <option value="0">bitte auswählen</option>
                                                <option value="1"<?= $sel1 ?>>Herr</option>
                                                <option value="2"<?= $sel2 ?>>Frau</option>
                                        </select>
                                </div>
                                <!-- Clear Div -->
                        <div class="clear"></div>
                        <!-- Clear Div End -->
                        </div>
                        <!-- Form element wrap end -->

                        <!-- Form element wrap -->
                        <div class="form-customer-create-input-wrap">
                                <div class="form-customer-create-label">Titel</div>
                                <div class="form-customer-create-input">
                                    <?php
                                    if ( isset($_POST['titel']) ){
                                            switch ( $_POST['titel'] ){
                                                case "1": $sel1 = " selected"; break;
                                                case "2": $sel2 = " selected"; break;
                                                case "3": $sel3 = " selected"; break;
                                                case "4": $sel4 = " selected"; break;
                                                default:  $sel1 = ""; $sel2 = ""; $sel3 = ""; $sel4 = "";
                                            }
                                    }else{
                                            $sel1 = ""; $sel2 = ""; $sel3 = ""; $sel4 = "";
                                    }
                                    ?>
                                        <select name="titel">
                                                <option value="1"<?= $sel1 ?>>Kein Titel</option>
                                                <option value="2"<?= $sel2 ?>>Dr.</option>
                                                <option value="3"<?= $sel3 ?>>Prof.</option>
                                                <option value="4"<?= $sel4 ?>>Prof. Dr.</option>
                                        </select>
                                </div>
                        <!-- Clear Div -->
                        <div class="clear"></div>
                        <!-- Clear Div End -->
                        </div>
                        <!-- Form element wrap end -->
                        <!-- ########################################################## -->
                        
                        <!-- ########################################################## -->
                        <!-- Form element wrap -->
                        <div class="form-customer-create-input-wrap">
                                <div class="form-customer-create-label">Vorname*#</div>
                                <div class="form-customer-create-input"><input type="text" name="firstname" value="<?php if ( isset($_POST['firstname']) ){echo $_POST['firstname'];} ?>" /></div>
                        <!-- Clear Div -->
                        <div class="clear"></div>
                        <!-- Clear Div End -->
                        </div>
                        <!-- Form element wrap end -->

                        <!-- Form element wrap -->
                        <div class="form-customer-create-input-wrap">
                                <div class="form-customer-create-label">Nachname*#</div>
                                <div class="form-customer-create-input"><input type="text" name="lastname" value="<?php if ( isset($_POST['lastname']) ){echo $_POST['lastname'];} ?>" /></div>
                        <!-- Clear Div -->
                        <div class="clear"></div>
                        <!-- Clear Div End -->
                        </div>
                        <!-- Form element wrap end -->

                        <!-- ########################################################## -->
                        
                        <!-- ########################################################## -->
                        
                        <!-- Form element wrap -->
                        <div class="form-customer-create-input-wrap">
                                <div class="form-customer-create-label">Geburtsname</div>
                                <div class="form-customer-create-input"><input type="text" name="birthname" value="<?php if ( isset($_POST['birthname']) ){echo $_POST['birthname'];} ?>" /></div>
                        <!-- Clear Div -->
                        <div class="clear"></div>
                        <!-- Clear Div End -->
                        </div>
                        <!-- Form element wrap end -->

                        <!-- Form element wrap -->
                        <div class="form-customer-create-input-wrap">
                                <div class="form-customer-create-label">Stra&szlig;e, Nr*</div>
                                <div class="form-customer-create-input"><input type="text" name="adress" value="<?php if ( isset($_POST['adress']) ){echo $_POST['adress'];} ?>" /></div>
                        <!-- Clear Div -->
                        <div class="clear"></div>
                        <!-- Clear Div End -->
                        </div>
                        <!-- Form element wrap end -->

                        <!-- ########################################################## -->
                        
                        <!-- ########################################################## -->
                        
                        <!-- Form element wrap -->
                        <div class="form-customer-create-input-wrap">
                                <div class="form-customer-create-label">PLZ*</div>
                                <div class="form-customer-create-input"><input type="text" name="zipcode" value="<?php if ( isset($_POST['zipcode']) ){echo $_POST['zipcode'];} ?>" /></div>
                        <!-- Clear Div -->
                        <div class="clear"></div>
                        <!-- Clear Div End -->
                        </div>
                        <!-- Form element wrap end -->

                        <!-- Form element wrap -->
                        <div class="form-customer-create-input-wrap">
                                <div class="form-customer-create-label">Stadt*</div>
                                <div class="form-customer-create-input"><input type="text" name="city" value="<?php if ( isset($_POST['city']) ){echo $_POST['city'];} ?>" /></div>
                        <!-- Clear Div -->
                        <div class="clear"></div>
                        <!-- Clear Div End -->
                        </div>
                        <!-- Form element wrap end -->

                        <!-- ########################################################## -->
                        
                        <!-- ########################################################## -->
                        
                        <!-- Form element wrap -->
                        <div class="form-customer-create-input-wrap">
                                <div class="form-customer-create-label">Wohnhaft seit*</div>
                                <div class="form-customer-create-input"><input id="datepicker_livingsince" type="text" name="livingsince" value="<?php if ( isset($_POST['livingsince']) ){echo $_POST['livingsince'];} ?>" /></div>
                        <!-- Clear Div -->
                        <div class="clear"></div>
                        <!-- Clear Div End -->
                        </div>
                        <!-- Form element wrap end -->

                        <!-- Form element wrap -->
                        <div class="form-customer-create-input-wrap">
                                <div class="form-customer-create-label">Geburtsdatum*</div>
                                <div class="form-customer-create-input"><input id="datepicker_birthday" type="text" name="birthdate" value="<?php if ( isset($_POST['birthdate']) ){echo $_POST['birthdate'];} ?>"/></div>
                        <!-- Clear Div -->
                        <div class="clear"></div>
                        <!-- Clear Div End -->
                        </div>
                        <!-- Form element wrap end -->

                        <!-- ########################################################## -->
                        
                        <!-- ########################################################## -->
                        
                        <!-- Form element wrap -->
                        <div class="form-customer-create-input-wrap">
                                <div class="form-customer-create-label">Familienstand*</div>
                                <div class="form-customer-create-input">
                                    <?php
                                    if ( isset($_POST['fam_stand']) ){
                                            switch ( $_POST['fam_stand'] ){
                                                case "1": $sel1 = " selected"; break;
                                                case "2": $sel2 = " selected"; break;
                                                case "3": $sel3 = " selected"; break;
                                                case "4": $sel4 = " selected"; break;
                                                case "5": $sel5 = " selected"; break;
                                                case "6": $sel6 = " selected"; break;
                                                default:  $sel1 = ""; $sel2 = ""; $sel3 = ""; $sel4 = ""; $sel5 = ""; $sel6 = "";
                                            }
                                    }else{
                                            $sel1 = ""; $sel2 = ""; $sel3 = ""; $sel4 = ""; $sel5 = ""; $sel6 = "";
                                    }
                                    ?>
                                        <select name="fam_stand">
                                                <option value="0">bitte auswählen</option>
                                                <option value="1"<?= $sel1 ?>>Ledig</option>
                                                <option value="2"<?= $sel2 ?>>Verheiratet</option>
                                                <option value="3"<?= $sel3 ?>>Geschieden</option>
                                                <option value="4"<?= $sel4 ?>>Zusammenlebend</option>
                                                <option value="5"<?= $sel5 ?>>Getrennt lebend</option>
                                                <option value="6"<?= $sel6 ?>>verwitwet</option>
                                        </select>
                                </div>
                        <!-- Clear Div -->
                        <div class="clear"></div>
                        <!-- Clear Div End -->
                        </div>
                        <!-- Form element wrap end -->

                        <!-- Form element wrap -->
                        <div class="form-customer-create-input-wrap">
                                <div class="form-customer-create-label">Staatsangeh&ouml;rigkeit*</div>
                                <div class="form-customer-create-input"><input type="text" name="nacionality" value="<?php if ( isset($_POST['nacionality']) ){echo $_POST['nacionality'];} ?>" /></div>
                        <!-- Clear Div -->
                        <div class="clear"></div>
                        <!-- Clear Div End -->
                        </div>
                        <!-- Form element wrap end -->

                        <!-- ########################################################## -->

                        <!-- ########################################################## -->
                        
                        <!-- Form element wrap -->
                        <div class="form-customer-create-input-wrap">
                                <div class="form-customer-create-label">Telefonnummer 1</div>
                                <div class="form-customer-create-input"><input type="text" name="phone_1" value="<?php if ( isset($_POST['phone_1']) ){echo $_POST['phone_1'];} ?>" /></div>
                        <!-- Clear Div -->
                        <div class="clear"></div>
                        <!-- Clear Div End -->
                        </div>
                        <!-- Form element wrap end -->

                        <!-- Form element wrap -->
                        <div class="form-customer-create-input-wrap">
                                <div class="form-customer-create-label">Telefonnummer 2</div>
                                <div class="form-customer-create-input"><input type="text" name="phone_2" value="<?php if ( isset($_POST['phone_2']) ){echo $_POST['phone_2'];} ?>" /></div>
                        <!-- Clear Div -->
                        <div class="clear"></div>
                        <!-- Clear Div End -->
                        </div>
                        <!-- Form element wrap end -->

                        <!-- ########################################################## -->
                        
                        <!-- ########################################################## -->
                        
                        <!-- Form element wrap -->
                        <div class="form-customer-create-input-wrap">
                                <div class="form-customer-create-label">E-Mail</div>
                                <div class="form-customer-create-input"><input type="text" name="email" value="<?php if ( isset($_POST['email']) ){echo $_POST['email'];} ?>" /></div>
                        <!-- Clear Div -->
                        <div class="clear"></div>
                        <!-- Clear Div End -->
                        </div>
                        <!-- Form element wrap end -->

                        <!-- Form element wrap -->
                        <div class="form-customer-create-input-wrap">
                                <div class="form-customer-create-label">&nbsp;</div>
                                <div class="form-customer-create-input">&nbsp;</div>
                        <!-- Clear Div -->
                        <div class="clear"></div>
                        <!-- Clear Div End -->
                        </div>
                        <!-- Form element wrap end -->

                        <!-- ########################################################## -->
                        
                        <!-- FORM-HEADLINE -->
                        <div class="form-customer-create-headline">Zusatz angaben</div>
                        <!-- FORM-HEADLINE END -->

                        <!-- ########################################################## -->
                        
                        <!-- Form element wrap -->
                        <div class="form-customer-create-input-wrap">
                                <div class="form-customer-create-label">Monatseinkommen*</div>
                                <div class="form-customer-create-input"><input type="text" name="month" value="<?php if ( isset($_POST['month']) ){echo $_POST['month'];} ?>" /></div>
                        <!-- Clear Div -->
                        <div class="clear"></div>
                        <!-- Clear Div End -->
                        </div>
                        <!-- Form element wrap end -->

                        <!-- Form element wrap -->
                        <div class="form-customer-create-input-wrap">
                                <div class="form-customer-create-label">Extra-Einkommen*</div>
                                <div class="form-customer-create-input"><input type="text" name="extra" value="<?php if ( isset($_POST['extra']) ){echo $_POST['extra'];} ?>" /></div>
                        <!-- Clear Div -->
                        <div class="clear"></div>
                        <!-- Clear Div End -->
                        </div>
                        <!-- Form element wrap end -->

                        <!-- ########################################################## -->
                        
                        <!-- ########################################################## -->
                        
                        <!-- Form element wrap -->
                        <div class="form-customer-create-input-wrap">
                                <div class="form-customer-create-label">Wohnsituation*</div>
                                <div class="form-customer-create-input">
                                    <?php
                                    if ( isset($_POST['living_at']) ){
                                            switch ( $_POST['living_at'] ){
                                                case "1": $sel1 = " selected"; break;
                                                case "2": $sel2 = " selected"; break;
                                                case "3": $sel3 = " selected"; break;
                                                default: $sel1 = ""; $sel2 = ""; $sel3 = "";
                                            }
                                    }else{
                                            $sel1 = ""; $sel2 = ""; $sel3 = "";
                                    }
                                    ?>
                                        <select name="living_at">
                                                <option value="0">bitte auswählen</option>
                                                <option value="1"<?= $sel1 ?>>Miete</option>
                                                <option value="2"<?= $sel2 ?>>Eltern</option>
                                                <option value="3"<?= $sel3 ?>>Eigentum</option>
                                        </select>
                                </div>
                        <!-- Clear Div -->
                        <div class="clear"></div>
                        <!-- Clear Div End -->
                        </div>
                        <!-- Form element wrap end -->

                        <!-- Form element wrap -->
                        <div class="form-customer-create-input-wrap">
                                <div class="form-customer-create-label">Berufsgruppe*</div>
                                <div class="form-customer-create-input">
                                        <select id="sector_group" name="sector_group">
                                            <option value="9999">bitte auswählen</option>
                                            <?php
                                            foreach ( $berufsgruppe as $value ){
                                                    if ( isset($_POST['sector_group']) ){
                                                            if ( $_POST['sector_group'] == $value['idBerufsgruppe'] ){
                                                                    $selected = " selected";
                                                            }else{
                                                                    $selected = "";
                                                            }
                                                    }else{
                                                            $selected = "";
                                                    }
                                                    echo "<option value=\"".$value['idBerufsgruppe']."\"$selected>".$value['bezeichnung']."</option>\n";
                                            }
                                            ?>
                                        </select>
                                </div>
                        <!-- Clear Div -->
                        <div class="clear"></div>
                        <!-- Clear Div End -->
                        </div>
                        <!-- Form element wrap end -->

                        <!-- ########################################################## -->
                        
                        <!-- ########################################################## -->
                        
                        <!-- Form element wrap -->
                        <div id="sector" class="form-customer-create-input-wrap">
                                <div class="form-customer-create-label">Branche</div>
                                <div class="form-customer-create-input">
                                        <select id="sb_sector" name="sector">
                                            <option value="9999">bitte auswählen</option>
                                            <?php
                                            foreach ( $branchen as $value ){
                                                    if ( isset($_POST['sector']) ){
                                                            if ( $_POST['sector'] == $value['idBranche'] ){
                                                                $selected = " selected";
                                                            }else{
                                                                $selected = "";
                                                            }
                                                    }else{
                                                            $selected = "";
                                                    }
                                                    echo "<option value=\"".$value['idBranche']."\"$selected>".$value['bezeichnung']."</option>\n";
                                            }
                                            ?>
                                        </select>
                                </div>
                        <!-- Clear Div -->
                        <div class="clear"></div>
                        <!-- Clear Div End -->
                        </div>
                        <!-- Form element wrap end -->

                        <!-- Form element wrap -->
                        <div id="occupation" class="form-customer-create-input-wrap">
                                <div id="label_occupation" class="form-customer-create-label">Beruf</div>
                                <div class="form-customer-create-input">
                                    <select id="sb_occupation" name="occupation">
                                            <option value="9999">bitte auswählen</option>
                                            <?php
                                            foreach ( $berufe as $value ){
                                                    if ( isset($_POST['occupation']) ){
                                                            if ( $_POST['occupation'] == $value['idBeruf'] ){
                                                                    $selected = " selected";
                                                            }else{
                                                                    $selected = "";
                                                            }
                                                    }else{
                                                            $selected = "";
                                                    }
                                                    echo "<option value=\"".$value['idBeruf']."\"$selected>".$value['bezeichnung']."</option>\n";
                                            }
                                            ?>
                                        </select>
                                </div>
                        <!-- Clear Div -->
                        <div class="clear"></div>
                        <!-- Clear Div End -->
                        </div>
                        <!-- Form element wrap end -->

                        <!-- ########################################################## -->

                        <!-- FORM-HEADLINE -->
                        <div class="form-customer-create-headline">Intern</div>
                        <!-- FORM-HEADLINE END -->

                        <!-- ########################################################## -->

                        <!-- Form element wrap -->
                        <div class="form-customer-create-input-wrap">
                                <div class="form-customer-create-label">Einwilligung wurde abgegeben</div>
                                <div class="form-customer-create-input"><input type="checkbox" name="privacy" value="accepted" <?php if ( isset($_POST['privacy']) ){echo "checked"; } ?>/></div>
                        <!-- Clear Div -->
                        <div class="clear"></div>
                        <!-- Clear Div End -->
                        </div>
                        <!-- Form element wrap end -->

                        <!-- Form element wrap -->
                        <div class="form-customer-create-input-wrap">
                                <div class="form-customer-create-label">Betreuer</div>
                                <div class="form-customer-create-input">
                                        <select name="advisor">
                                            <option value="9999">bitte auswählen</option>
                                            <?php
                                            foreach ( $betreuer as $value ){
                                                    if ( isset($_POST['advisor']) ){
                                                            if ( $_POST['advisor'] == $value['idMitarbeiter'] ){
                                                                    $selected = " selected";
                                                            }else{
                                                                    $selected = "";
                                                            }
                                                    }else{
                                                            $selected = "";
                                                    }
                                                    echo "<option value=\"".$value['idMitarbeiter']."\"$selected>".utf8_encode($value['name']).", ".utf8_encode($value['vorname'])."</option>\n";
                                            }
                                            ?>
                                        </select>
                                </div>
                        <!-- Clear Div -->
                        <div class="clear"></div>
                        <!-- Clear Div End -->
                        </div>
                        <!-- Form element wrap end -->

                        <!-- ########################################################## -->
                        
                        <!-- ########################################################## -->
                        
                        <!-- Form element wrap -->
                        <div class="form-customer-create-submit-wrap">
                                <div>* Pflichtfelder für die Vormerkung zur Freigabe<br /># Pflichtfelder für das unvolständige Speichern</div>
                                <div class="form-customer-create-submit">
                                    <input class="form-customer-create-button" type="submit" name="abort" value="Abbrechen"/>
                                    <input class="form-customer-create-button" type="submit" name="save" value="Speichern"/>
                                    <input class="form-customer-create-button" type="submit" name="mark" value="zur Freigabe vormerken"/>
                                </div>
                        </div>

                        <!-- Clear Div -->
                        <div class="clear"></div>
                        <!-- Clear Div End -->
                        </div>
                        <!-- Form element wrap end -->
                        
                        <!-- ########################################################## -->

                </form>
                <!-- Form End -->
        </div>
        <!-- 2 columns end -->


<!-- EDIT FORM END -->
<?php } // end-if($show_editForm)


?>

<!-- JAVASCRIPT -->
<script>
    $(function() {
            $( "#datepicker_livingsince" ).datepicker({ dateFormat: 'dd.mm.yy' });
            $( "#datepicker_birthday" ).datepicker({ dateFormat: 'dd.mm.yy' });
    });
    //dasdasd
    $(document).ready(function(){

            $("#sector_group").change(onSelectChange_sector_group);
            
            onSelectChange_sector_group();

    });
    function onSelectChange_sector_group(){
            var sector_group = $("#sector_group option:selected");
            
            if( sector_group.val() == 1 || sector_group.val() == 2 ||
                sector_group.val() == 3 || sector_group.val() == 4 ||
                sector_group.val() == 5 || sector_group.val() == 11
            ){
                $("#sector").show();
                if( sector_group.val() == 5 || sector_group.val() == 11 ){
                    $("#occupation").show();
                    $("#sector").width(385);
                }else{
                    $("#sector").width(770);
                    $("#occupation").hide();
                    $("#sb_occupation").val(0);
                }
                
            }else{
                $("#sb_sector").val(0);
                $("#sector").hide();
                $("#sector").width(385);
                
                $("#sb_occupation").val(0);
                $("#occupation").hide();
            }
    }
</script>
<!-- JAVASCRIPT END -->